﻿//创建全局组件  给他定义一个名字 名字只能为字母 fenye 小写或 -
Vue.component("fenye", {
    //用来放   编写模板内容 这个是  转义符=``
    template:
        `<div id="pageDiv">
                    <div id = "leftPage"> 共有{{ rows }}条记录，当前第{{ cpage }}/{{pages}}页</div >
                    <ul id="ul1" class="pagination">
                    <li><a>&laquo;</a></li>
                    <li><a v-on:click="Shou()">首页</a></li>
                    <li><a v-on:click="Shang()">上一页</a></li >
                    <li><a v-on:click="Xia()">下一页</a></li >
                    <li><a v-on:click="Wei()">尾页</a></li >
                    <li><a href="#">&raquo;</a></li></ul >
        </div>`,
    props: ['rows', 'currentpage', 'pages'],
    data: function () {
        return {
            cpage: 1
        }
    },
    methods: {
        load: function () {
            var t = this;
            $.ajax({
                url: "/Position/FenYe?cpage=" + t.cpage,
                type: "get",
                success: function (msg) {
                    var datas = eval("("+msg+")");
                    datas["currentpage"] = t.cpage;
                    console.info(datas);
                    t.$emit('ss', datas);//子传父
                }
            });
        },
        Shou: function () {
            var t = this;
            t.cpage = 1;
            t.load();
        },
        Shang: function () {
            var t = this;
            if (t.cpage > 1) {
                t.cpage--;
            } else {
                t.cpage == 1;
            }
            t.load();
        },
        Xia: function () {
            var t = this;
            if (t.cpage < t.pages) {
                t.cpage++;
            } else {
                t.cpage = t.pages;
            }
            t.load();
        },
        Wei: function () {
            var t = this;
            t.cpage = t.pages;
            t.load();
        }
    }

});